package com.newbie.cellsms.service;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * 用来调用本地sh脚本文件的
 * 
 * @author Jacarri
 * 
 */
public class NativeCallService {

	public static void startDevice() {

	}

	public void execCommand(String cmds) {
		try {
			Process ps = Runtime.getRuntime().exec(cmds);
			System.out.print(loadStream(ps.getInputStream()));
			System.err.print(loadStream(ps.getErrorStream()));
		} catch (IOException ioe) {
			ioe.printStackTrace();
		}
	}

	// read an input-stream into a String
	static String loadStream(InputStream in) throws IOException {
		int ptr = 0;
		in = new BufferedInputStream(in);
		StringBuffer buffer = new StringBuffer();
		while ((ptr = in.read()) != -1) {
			buffer.append((char) ptr);
		}
		return buffer.toString();

	}
}
